home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qpixmap.h.z / qpixmap.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.9 KB  |  234 lines

  1. /****************************************************************************
  2. ** $Id: qpixmap.h,v 2.22 1998/07/03 00:09:37 hanord Exp $
  3. **
  4. ** Definition of QPixmap class
  5. **
  6. ** Created : 940501
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QPIXMAP_H
  25. #define QPIXMAP_H
  26.  
  27. #ifndef QT_H
  28. #include "qpaintdevice.h"
  29. #include "qcolor.h"
  30. #include "qstring.h"
  31. #endif // QT_H
  32.  
  33.  
  34. class QPixmap : public QPaintDevice        // pixmap class
  35. {
  36. friend class QPaintDevice;
  37. friend class QPainter;
  38. public:
  39.     enum ColorMode { Auto, Color, Mono };
  40.  
  41.     QPixmap();
  42.     QPixmap( int w, int h,  int depth=-1 );
  43.     QPixmap( const QSize &, int depth=-1 );
  44.     QPixmap( const char *fileName, const char *format=0, ColorMode mode=Auto );
  45.     QPixmap( const char *fileName, const char *format, int conversion_flags );
  46.     QPixmap( const char *xpm[] );
  47.     QPixmap( const QPixmap & );
  48.    ~QPixmap();
  49.  
  50.     QPixmap    &operator=( const QPixmap & );
  51.     QPixmap    &operator=( const QImage     & );
  52.  
  53.     bool    isNull()    const;
  54.  
  55.     int        width()        const { return data->w; }
  56.     int        height()    const { return data->h; }
  57.     QSize    size()        const { return QSize(data->w,data->h); }
  58.     QRect    rect()        const { return QRect(0,0,data->w,data->h); }
  59.     int        depth()        const { return data->d; }
  60.     static int    defaultDepth();
  61.  
  62.     void    fill( const QColor &fillColor=white );
  63.     void    fill( const QWidget *, int xofs, int yofs );
  64.     void    fill( const QWidget *, const QPoint &ofs );
  65.     void    resize( int width, int height );
  66.     void    resize( const QSize & );
  67.  
  68.     const QBitmap *mask() const;
  69.     void    setMask( const QBitmap & );
  70.     bool    selfMask() const;
  71.     QBitmap    createHeuristicMask( bool clipTight = TRUE ) const;
  72.  
  73.     static  QPixmap  grabWindow( WId, int x=0, int y=0, int w=-1, int h=-1 );
  74.  
  75.     QPixmap        xForm( const QWMatrix & ) const;
  76.     static QWMatrix trueMatrix( const QWMatrix &, int w, int h );
  77.  
  78.     QImage    convertToImage() const;
  79.     bool    convertFromImage( const QImage &, ColorMode mode=Auto );
  80.     bool    convertFromImage( const QImage &, int conversion_flags );
  81.  
  82.     static const char *imageFormat( const char *fileName );
  83.     bool    load( const char *fileName, const char *format=0,
  84.               ColorMode mode=Auto );
  85.     bool    load( const char *fileName, const char *format,
  86.               int conversion_flags );
  87.     bool    loadFromData( const uchar *buf, uint len,
  88.                   const char *format=0,
  89.                   ColorMode mode=Auto );
  90.     bool    loadFromData( const uchar *buf, uint len,
  91.                   const char *format,
  92.                   int conversion_flags );
  93.     bool    loadFromData( QByteArray data,
  94.                   const char *format=0,
  95.                   int conversion_flags=0 );
  96.     bool    save( const char *fileName, const char *format ) const;
  97.  
  98. #if defined(_WS_WIN_) || defined(_WS_PM_)
  99.     HANDLE    hbm()        const;
  100. #endif
  101.  
  102.     int        serialNumber()    const;
  103.  
  104.     enum Optimization { NoOptim, NormalOptim, BestOptim };
  105.  
  106.     Optimization    optimization() const;
  107.     void        setOptimization( Optimization );
  108.     static Optimization defaultOptimization();
  109.     static void        setDefaultOptimization( Optimization );
  110.     
  111. #if 1
  112.     bool    isOptimized()    const;
  113.     void    optimize( bool );
  114.     static bool isGloballyOptimized();
  115.     static void optimizeGlobally( bool );
  116. #endif
  117.  
  118.     virtual void detach();
  119.  
  120.     bool    isQBitmap()    const;
  121.  
  122. protected:
  123.     QPixmap( int w, int h, const uchar *data, bool isXbitmap );
  124.     int        metric( int ) const;
  125.  
  126. #if defined(_WS_WIN_)
  127.     HANDLE    allocMemDC();
  128.     void    freeMemDC();
  129. #endif
  130.  
  131.     struct QPixmapData : public QShared {    // internal pixmap data
  132.     QCOORD    w, h;
  133.     short    d;
  134.     uint    unused     : 1;
  135.     uint    optim     : 1;
  136.     uint    uninit     : 1;
  137.     uint    bitmap     : 1;
  138.     uint    selfmask : 1;
  139.     int    ser_no;
  140.     QBitmap *mask;
  141. #if defined(_WS_WIN_)
  142.     HANDLE    hbm;
  143.     void   *bits;
  144.     QPixmap *maskpm;
  145. #elif defined(_WS_PM_)
  146.     HANDLE    hdcmem;
  147.     HANDLE    hbm;
  148. #elif defined(_WS_X11_)
  149.     void   *ximage;
  150.     void   *maskgc;
  151. #endif
  152.     Optimization opt;
  153.     } *data;
  154.  
  155. private:
  156.     void    init( int, int, int );
  157.     void    deref();
  158.     QPixmap    copy() const;
  159.     static bool optimAll;
  160.     static Optimization defOpt;
  161.     friend void bitBlt( QPaintDevice *, int, int, const QPaintDevice *,
  162.             int, int, int, int, RasterOp, bool );
  163.     friend void bitBlt( QPaintDevice *, int, int, const QImage* src,
  164.             int, int, int, int, int conversion_flags );
  165. };
  166.  
  167.  
  168. inline bool QPixmap::isNull() const
  169. {
  170. #if defined(_WS_X11_)
  171.     return hd == 0;
  172. #else
  173.     return data->hbm == 0;
  174. #endif
  175. }
  176.  
  177. inline void QPixmap::fill( const QWidget *w, const QPoint &ofs )
  178. {
  179.     fill( w, ofs.x(), ofs.y() );
  180. }
  181.  
  182. inline void QPixmap::resize( const QSize &s )
  183. {
  184.     resize( s.width(), s.height() );
  185. }
  186.  
  187. inline const QBitmap *QPixmap::mask() const
  188. {
  189.     return data->mask;
  190. }
  191.  
  192. inline bool QPixmap::selfMask() const
  193. {
  194.     return data->selfmask;
  195. }
  196.  
  197. #if defined(_WS_WIN_) || defined(_WS_PM_)
  198. inline HANDLE QPixmap::hbm() const
  199. {
  200.     return data->hbm;
  201. }
  202. #endif
  203.  
  204. inline int QPixmap::serialNumber() const
  205. {
  206.     return data->ser_no;
  207. }
  208.  
  209. inline QPixmap::Optimization QPixmap::optimization() const
  210. {
  211.     return data->opt;
  212. }
  213.  
  214. inline bool QPixmap::isOptimized() const
  215. {
  216.     return data->optim;
  217. }
  218.  
  219. inline bool QPixmap::isQBitmap() const
  220. {
  221.     return data->bitmap;
  222. }
  223.  
  224.  
  225. /*****************************************************************************
  226.   QPixmap stream functions
  227.  *****************************************************************************/
  228.  
  229. QDataStream &operator<<( QDataStream &, const QPixmap & );
  230. QDataStream &operator>>( QDataStream &, QPixmap & );
  231.  
  232.  
  233. #endif // QPIXMAP_H
  234.